package com.study.lock;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

import org.junit.Test;

public class LockDemo extends Thread{
	
	@Test
	public void test3() throws Exception{
	    final Lock lock=new ReentrantLock();
	    
	    Thread t1=new Thread(new Runnable(){
	        @Override
	        public void run() {
	            
	        	try {
	        		//lock.lock(); //简单加锁
					lock.lockInterruptibly(); //在等待获取锁的过程中休眠并禁止一切线程调度
					//Thread.sleep(5000);
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
	            System.out.println(Thread.currentThread().getName()+" interrupted.");
	        }
	    });
	    t1.start();
	    Thread.sleep(1000);
	    t1.interrupt();
	    //Thread.sleep(5000);
	}
}
